<!--
 * @Author: 王明明834578987 10266004+wang-mingming-834578987@user.noreply.gitee.com
 * @Date: 2024-08-29 10:59:23
 * @LastEditors: 王明明834578987 10266004+wang-mingming-834578987@user.noreply.gitee.com
 * @LastEditTime: 2024-09-11 09:09:45
 * @FilePath: \ft-apply-admin\src\views\applicationDetails\RTComponent\InterviewTache\Train\TrainComponent\Training.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="btns">
    <Button v-auth="'trainingEvaluate'" color="#6C7DA8" @click="comment">培训评价</Button>
    <Button v-auth="'midwayQuit'" color="error" @click="dieout">中途淘汰</Button>
    <Button v-auth="'midwayWaive'" color="warning" @click="surrender">中途放弃</Button>
  </div>

  <BasicModal :show="show" :title="title" width="30%" :widthComfirm="true" @comfirm="comfirm"
    @closeModal="show = false">
    <template #content>
      <CommonForm :formList="formList" ref="formRef"></CommonForm>
    </template>
  </BasicModal>

</template>

<script setup lang='ts'>
import { ref } from "vue";
import { Button } from "@/components/Button";
import BasicModal from "@/views/ApplicationDetails/Modals/BasicModal.vue";
import type { IndexFormItem } from "@/views/ApplicationDetails/application-type.ts";
import CommonForm from "@/views/applicationDetails/CommonForm.vue";
import { message } from "ant-design-vue";
import { trainingProgress } from "@/api/application-details/index.ts";
import { comStores } from '@/store/common/comStore';
const store = comStores()
const { userName } = store.userInFor


const formList = ref<IndexFormItem[]>([
  { label: "培训评价", name: "reason", value: "", component: 'dateRange' },
])
const title = ref<string>('新增培训评价')
const show = ref<boolean>(false);
const formRef = ref<any>(null)
const comment = () => {
  title.value = '新增培训评价'
  show.value = true
  console.log('评价 addcomment')
  formList.value = [{ label: "培训评价", name: "assess", value: "", component: 'textarea' }]
}
const surrender = () => {
  show.value = true
  title.value = '中途放弃'
  formList.value = [{ label: "放弃原因", name: "reason", value: "", component: 'textarea', required: false }]
}
const dieout = () => {
  show.value = true
  title.value = '中途淘汰'
  console.log('dieout 培训中')
  formList.value = [{ label: "淘汰原因", name: "reason", value: "", component: 'textarea', required: false }]
}
const comfirm = async () => {
  const res = await formRef.value.submitForm();
  if (!res) return;
  console.log(res, '===>res')
  const { resumeId, processId } = store.currentResume;
  let result = "";
  let param: any = {
    resumeId: resumeId,
    processId: processId,
    result: result,
    operator: userName
  }
  if (title.value == '新增培训评价') {
    param.assess = res[0].value
  }
  if (title.value == '中途放弃') {
    param.result = '放弃'
    param.reason = res[0].value
  }
  if (title.value == '中途淘汰') {
    param.result = '淘汰';
    param.reason = res[0].value
  }
  // reason: res[0].value,
  const data = await trainingProgress(param);
  if (data && data.code === '10000') {
    message.success("操作成功");
    show.value = false;
    store.getResumeInfo(resumeId);
    store.$patch({
      noticeNumber:Math.random()
    })
    formList.value.forEach(el => {
      el.value = ""
    })
  } else {
    message.error(data.msg)
  }
}

</script>
<style lang="less" scoped>
.btns {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
</style>
